<!--
 * @Author: mhb
 * @Date: 2021-12-21 17:38:02
 * @LastEditTime: 2022-01-12 10:26:34
 * @LastEditors: Please set LastEditors
 * @Description: 成果发布
 * @FilePath: \cscec-pms-admin-3\src\views\quality\resultsManagement\QCActivityResult\ReleaseResult.vue
-->
<template>
  <div>
    <div class="mb20">
      <title-name title="活动成果"></title-name>
      <a-table
        :row-selection="{
          type: 'checkbox',
          selectedRowKeys: selectedRowKeys,
          onChange: (keys, rows) => {
            selectedRowKeys = keys
            selectedRows = rows
          },
          getCheckboxProps: (record) => ({
            props: { disabled: record.status === '已发布' }
          })
        }"
        ref="table"
        rowKey="id"
        :dataSource="form.achievements || []"
        :pagination="false"
        :columns="columns"
      >
        <!-- 操作：移除 -->
        <a
          slot="actions"
          slot-scope="text, record"
          @click="
            chooseRow = record
            $refs.viewResultData.visible = true
          "
          >查看</a
        >
      </a-table>
    </div>
    <!-- 成果评审详情信息弹窗 -->
    <ViewResultData ref="viewResultData" :form="chooseRow" />
  </div>
</template>

<script>
import ViewResultData from '../components/ViewResultData' // 表单弹窗

export default {
  name: 'ReleaseResults',
  components: {
    ViewResultData
  },
  props: {
    // 表单
    form: {
      type: Object,
      default: () => {}
    },
    // 请求api
    api: {
      type: Object,
      default: () => null
    }
  },
  data() {
    return {
      selectedRows: [], // 成果信息选中集合
      selectedRowKeys: [], // 成果信息选中id集合
      chooseRow: {}, //选中活动成果
      columns: [
        {
          dataIndex: 'projectName',
          title: '项目名称'
        },
        {
          dataIndex: 'topicName',
          title: '课题名称'
        },
        {
          dataIndex: 'topicTypeName',
          title: '课题类型'
        },
        {
          dataIndex: 'topicRegisterNumber',
          title: '课题注册号'
        },
        {
          dataIndex: 'completeEmployeeNames',
          title: '课题实际完成人'
        },
        {
          dataIndex: 'average',
          title: '资料平均分'
        },
        {
          dataIndex: 'deductPoints',
          title: '资料逾期扣分'
        },
        {
          dataIndex: 'score',
          title: '资料得分',
          customRender(e){
            return e > 0 ? e : 0
          }
        },
        {
          dataIndex: 'sort',
          title: '排名',
          sorter: (a, b) => a.sort - b.sort
        },
        {
          dataIndex: 'status',
          title: '状态',
          customRender(e) {
            return e === '已发布' ? e : '未发布'
          }
        },
        {
          dataIndex: 'actions',
          title: '操作',
          width: 80,
          scopedSlots: { customRender: 'actions' }
        }
      ], // 成果表头
      columns2: [
        {
          title: '姓名',
          ellipsis: true,
          dataIndex: 'name'
        },
        {
          title: '职称',
          ellipsis: true,
          dataIndex: 'jobTitle',
          customRender(e) {
            return e || '无'
          }
        },
        {
          title: '岗位',
          ellipsis:true,
          dataIndex: 'postPNames',
          customRender(e) {
            return e || '无'
          }
        },
        {
          title: '学历',
          ellipsis: true,
          dataIndex: 'specialitieMax',
          customRender(e) {
            return e || '无'
          }
        }
      ] // 人员表头
    }
  },
  methods: {
    /**
     * 提交表单
     */
    handleSubmit() {
      let that = this
      // 校验
      if (!that.selectedRowKeys?.length) {
        that.$message.warning('请先勾选可发布的活动！')
      } else {
        let details = that.selectedRows?.map((i) => ({ reviewAchievementId: i.id })) // 发布列表
        let form = {
          details,
          id: that.form.id
        } // 表单
        that.$confirm({
          title: '温馨提示',
          content: `确定发布${that.selectedRows?.map(i=>`《${i.topicName}》`)?.join('，')}，发布后不可撤回？`,
          onOk: () => {
            // 提交表单
            return this.api.release(form).then((res) => {
              if (res.code === 200 || res.data.code === 200) {
                that.$message.success('发布成功！')
                that.$multiTab.close()
              }
            })
          }
        })
      }
    }
  }
}
</script>
